const { regeneratorRuntime, dayjs } = global

Page(global.connect(
  state => ({
    ...state.activityReducer
  }),
  dispatch => ({
    async adsPositionSelect(data) {
      return dispatch(global.activityReducer.adsPositionSelect(data))
    },
    async asyncAdsPostionSettingData(data) {
      return dispatch(global.activityReducer.asyncAdsPostionSettingData(data))
    },
    async asyncAdsPostionSettingSubmit(data) {
      return dispatch(global.activityReducer.asyncAdsPostionSettingSubmit(data))
    },
    async initCustomAdsPositionData(data) {
      return dispatch(global.activityReducer.initCustomAdsPositionData(data))
    },

  })
)({
  onLoad() {
    console.log(this.route)
  },
  onShow() {
  },
  handleLicon1Tap() {
    wx.navigateBack()
  },
  handleCustom() {
    global.handleRoute({ route: 'effect-custom' })
  },
  handleNextStep(e) {
    console.log('handleNextStep', e)
    const selects = this.data.storePosition.data.filter(i => i.selected)
    if (!selects.length) {
      this.selectComponent('#toast').handleShow({
        message: '请选择广告位'
      })
      return
    }
    global.handleRoute({ route: 'make-order-step3' })
  },
  handleAdsPositionSelect(e) {
    console.log('handleAdsPositionSelect', e)
    const { index } = e.currentTarget.dataset
    const selected = e.detail
    this.adsPositionSelect({
      index, selected
    })
  },
  handleAdsBlock(e) {
    console.log('handleAdsBlock', e)
    const { index, detail } = e.currentTarget.dataset

    const { storePosition } = this.data
    const positionDetail = storePosition.data[index]
    console.log(positionDetail)

    if (detail.ads_type == 1) {
      global.handleRoute({ route: 'mos-step0', query: { positionIndex: index } })
    }
    if (detail.ads_type == 2) {
      this.initCustomAdsPositionData(detail)
      global.handleRoute({ route: 'effect-custom' })
    }

    // const { index, type } = e.currentTarget.dataset
    // if (type === 2) {
    //   this.initCustomAdsPositionData({
    //     ...this.data.orderDetail.data.ads_info[index]
    //   })
    //   global.handleRoute({ route: 'effect-custom' })
    // } else {
    //   this.asyncAdsPostionSettingData({ index })
    //   global.handleRoute({ route: 'mos-step1' })
    // }

  },
}))